package com.szrt.day20170412.student.client;



import static org.junit.Assert.*;

import java.util.Scanner;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.szrt.day20170412.student.dao.StudentDao;
import com.szrt.day20170412.student.entity.StudentEntity;
import com.szrt.utils.ArrayUtil;

public class StudentDaoTest {
	
	
	/**
	 * 全局变量
	 */
	private StudentEntity[] students = new StudentEntity[5];
	
	private StudentDao dao = null;
	
	
	private Scanner scanner=null;
	
	
	@Test
	public void deletesTest() throws Exception {
		
		StudentEntity zjy=new StudentEntity();
		zjy.setName("张嘉源");
		zjy.setScore(46);
		
		StudentEntity lzh=new StudentEntity();
		lzh.setName("罗智壕");
		lzh.setScore(56);
		
		StudentEntity lhh=new StudentEntity();
		lhh.setName("林华华");
		lhh.setScore(33);
		
		
		StudentEntity[] del = new StudentEntity[3];
		
		del[0]=zjy;
		del[1]=lzh;
		del[2]=lhh;
		
		StudentEntity[] jieguo = dao.deletes(students, del);
		
		ArrayUtil.printArry(jieguo);
		
		
		
		
	}
	
	@Test
	public void updateStudentScoreTest(){
		
		String studentName="贾梦菊";
		double updateScore=60.5;
		StudentEntity entity = dao.updateStudentScore(students, studentName, updateScore);
		System.out.println(entity);
		
	}
	
	
	@After
	public void close(){
		
		scanner.close();
	}
	@Before
	public void init(){
		
		dao = new StudentDao();
		scanner = new Scanner(System.in);
		
		StudentEntity jmj=new StudentEntity();
		
		
		//?  aaaaa 处理不符合条件的情况  提示 重新输入?  死循环
		
		
		
		while(true){
			System.out.println("请输入学生的成绩...");
			String name = scanner.nextLine();
			if(name.length()>=2  && name.length()<=4){
				//如果输入的姓名符合条件  退出循环 否则
				jmj.setName(name);
				break;
			}else{
				System.out.println("您输入的名字不符合条件。请重新输入..");
			}
			
		}
		
		
		
		
		
		jmj.setName("贾梦菊");
		jmj.setScore(66);
		students[0]=jmj;
		
		StudentEntity zjy=new StudentEntity();
		zjy.setName("张嘉源");
		zjy.setScore(46);
		students[1]=zjy;
		
		StudentEntity lzh=new StudentEntity();
		lzh.setName("罗智壕");
		lzh.setScore(56);
		students[2]=lzh;
		
		StudentEntity hxq=new StudentEntity();
		hxq.setName("何小强");
		hxq.setScore(86);
		students[3]=hxq;
		
		StudentEntity jzh=new StudentEntity();
		jzh.setName("靳志辉");
		jzh.setScore(45);
		students[4]=jzh;
	}
	
	@Test
	public void findAllNGTest() throws Exception {
		
		
		//CTRL+SHIFT+O OPEN
		//StudentDao dao = new StudentDao();
		
		StudentEntity[] jgs = dao.findAllNG(students);
		
		ArrayUtil.printArry(jgs);
		
		
	}
	
	
	@Test
	public void findSix() throws Exception {
		
		
		//CTRL+SHIFT+O OPEN
		//StudentDao dao = new StudentDao();
		
		StudentEntity[] jgs = dao.findWH(students,9);
		
		ArrayUtil.printArry(jgs);
		
		
	}

}
